package com.evoupsight.monitorpass.perfs;

import org.antlr.v4.runtime.misc.NotNull;

import java.util.Stack;

public class MyDSLListener extends MonitorDSLBaseListener {
    private Stack<ExprNode> stacks = new Stack<>();

    @Override
    public void exitIdentifier(@NotNull MonitorDSLParser.IdentifierContext ctx) {
        stacks.push(new ExprNode(ExprType.ID, ctx.getText(), null, null));
    }

    @Override
    public void exitAndEpr(@NotNull MonitorDSLParser.AndEprContext ctx) {
        ExprNode right = stacks.pop();
        ExprNode left = stacks.pop();

        stacks.push(new ExprNode(ExprType.AND, null, left, right));
    }

    @Override
    public void exitOrEpr(@NotNull MonitorDSLParser.OrEprContext ctx) {
        ExprNode right = stacks.pop();
        ExprNode left = stacks.pop();

        stacks.push(new ExprNode(ExprType.OR, null, left, right));
    }

    @Override
    public void exitLine(@NotNull MonitorDSLParser.LineContext ctx) {
        super.exitLine(ctx);
    }

    @Override
    public void exitParenExpr(@NotNull MonitorDSLParser.ParenExprContext ctx) {
        // DO NOTHING
    }

    public ExprNode getResult() {
        return stacks.peek();
    }
}
